package com.effective;

import java.util.AbstractList;
import java.util.Date;
import java.util.List;

public class Super {
	public Super() {
		overrideMe();
	}

	protected void overrideIt() {
		callInner();
	}
	
	protected void overrideMe() {
		callInner();
	}
	
	private void callInner() {
		System.out.println(new Date());
	}
	
	protected void overridYou() {
		callInner();
	}
	
	static List<Integer> intArrayAsList(final int[] a){
		if(a == null) {
			throw new NullPointerException();
		}
		
		return new AbstractList<Integer>() {

			@Override
			public Integer get(int index) {
				return a[index];
			}
			
			@Override
			public Integer set(int index, Integer element) {
				int oldVal = a[index];
				a[index] = element;
				return oldVal;
			}

			@Override
			public int size() {
				return a.length;
			}
		};
	}
	
	
	private static class Sub extends Super{
		private Date date;
		
		public Sub(Date date) {
			this.date = date;
		}
		
		@Override
		protected void overrideMe() {
			System.out.println(date.getClass());
		}
	}
	
	public static void main(String[] args) {
		Sub s = new Sub(new Date());
		System.out.println(s);
	}
}
/**
 * Output:
 * Exception in thread "main" java.lang.NullPointerException
 */
